package com.cpxj.common;

import java.io.Serializable;

public final class YmmResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private boolean success;
    private int errorCode;
    private String errorMsg;
    private T data;

    public static <T> YmmResult<T> succResult(T data) {
        YmmResult<T> result = new YmmResult(true);
        result.setData(data);
        return result;
    }

    public static <T> YmmResult<T> succResult() {
        YmmResult<T> result = new YmmResult(true);
        return result;
    }

    public static <T> YmmResult<T> failResult(int errorCode, String errorMsg) {
        YmmResult<T> result = new YmmResult(false);
        result.setErrorCode(errorCode);
        result.setErrorMsg(errorMsg);
        return result;
    }


    public boolean isSuccess() {
        return this.success;
    }

    public YmmResult() {
    }

    private YmmResult(boolean success) {
        this.success = success;
    }

    public String getErrorMsg() {
        return this.errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getErrorCode() {
        return this.errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public String toString() {
        return "YmmResult [success=" + this.success + ", errorCode=" + this.errorCode + ", errorMsg=" + this.errorMsg + ", data=" + this.data + "]";
    }
}
